﻿//intercept API error responses
mainModule.config(["$httpProvider", "$provide", "notificationProvider", function ($httpProvider, $provide, notificationProvider) {
    "use strict";

    $httpProvider.interceptors.push(["$q", function ($q) {
        return {
            'response': function (response) {
                if (response.data && typeof(response.data.Success) !== "undefined")
                    notificationProvider.notify(response.data);
                return response;
            },
            'responseError': function (rejection) {
                notificationProvider.notifyError(rejection.config.url + "<br />" + rejection.data.Message);
                return $q.reject(rejection);
            }
        };
    }]);
        
    $provide.decorator("$exceptionHandler", ['$delegate', function ($delegate) {
        return function (exception, cause) {
            notificationProvider.notify(exception);
        };
    }]);
        
}]);
